<template>
    <div>
        <el-form label-width="85px" :model="form" label-position="right" ref="formRef" :rules="formRules"
            class="borderNone" disabled>
            <el-card>
                <el-row>
                    <el-col :xs="24" :sm="24" :md="24" :lg="8" :xl="8">
                        <el-form-item label="编号" prop="sendSampleNumber">
                            <el-input v-model="form.sendSampleNumber" disabled class="borderNone"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="10" :xl="10">
                        <el-form-item prop="materialQuality">
                            <template #label>
                                <span style="color: #f56c6c;margin-right: 4px;">*</span>
                                <span style="display:inline-block;">登记人员</span>
                            </template>
                            <el-input v-model="form.employeeName" disabled class="borderNone"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
                        <el-form-item label="反馈日期" prop="testDate">
                            <el-input v-model="form.testDate" class="borderNone"/>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :xs="24" :sm="24" :md="24" :lg="8" :xl="8">
                        <el-form-item prop="sampleAuditId">
                            <template #label>
                                <span style="color: #f56c6c;margin-right: 4px;">*</span>
                                <span style="display:inline-block;">送样单</span>
                            </template>
                            <el-input v-model="form.sendSampleNumber" disabled class="borderNone"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="10" :xl="10">
                        <el-form-item label="样品评审表" prop="testDate">
                            <span class="link-type" @click="toDetail">{{ form.sampleAuditNumber }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
                        <el-form-item label="客户名称" prop="custName">
                            <el-input v-model="form.custName" disabled class="borderNone"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-card>
            <el-card header="测试指标" style="margin-top: 10px;">
                <el-table  :data="dataList" ref="table" width="400" border stripe :header-cell-style="{ 'color': '#000' }">
                    <el-table-column label="样品编号" prop="sendSampleDtl.mtlNo" width="120">
                    </el-table-column>
                    <el-table-column label="样品名称" prop="sendSampleDtl.mtlName"></el-table-column>
                    <el-table-column label="样品规格" prop="sendSampleDtl.mtlSpec" width="120"></el-table-column>
                    <el-table-column label="送样数量" prop="sendSampleDtl.qty"></el-table-column>
                    <el-table-column label="模具" prop="moldName" width="120">
                    </el-table-column>
                    <el-table-column label="量产" align="center">
                        <el-table-column label="量产否" width="120" prop="ableProductName">
                        </el-table-column>
                        <el-table-column label="首次量产计划时间" prop="firstProductDate" width="120">
                        </el-table-column>
                        <el-table-column label="最后量产计划时间" prop="productDate" width="120">
                        </el-table-column>
                        <el-table-column label="不能量产原因" width="150" prop="notProductReason">
                        </el-table-column>
                    </el-table-column>
                    <el-table-column label="实际量产情况" align="center">
                        <el-table-column label="生产描述" width="150" prop="productDescription">
                        </el-table-column>
                        <el-table-column label="量产编码" prop="produceMtlNo" width="120">
                        </el-table-column>
                        <el-table-column label="量产图号" prop="produceDrawNo" width="120">
                        </el-table-column>
                        <el-table-column label="量产数量" width="120" prop="productAmount">
                        </el-table-column>
                        <el-table-column label="实际量产时间" width="120" prop="factProductDate">
                        </el-table-column>
                        <el-table-column label="生产状态" width="120" prop="productStatusName">
                        </el-table-column>
                    </el-table-column>
                    <template  v-for="(item,index) in testRequireList" :key="index">
                        <el-table-column :label="item.testParameterName">
                            <el-table-column label="客户要求">
                                <template #default="scope">
                                    <span>{{ scope.row.itemList[index].custRequire }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="我司达到" width="120">
                                <template #default="scope">
                                    <span>{{ scope.row.itemList[index].testResult }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="是否通过" width="120">
                                <template #default="scope">
                                    <span>{{ scope.row.itemList[index].passedStatusName }}</span>
                                </template>
                            </el-table-column>
                        </el-table-column>
                    </template>
                    <el-table-column label="是否全部通过" width="120" prop="sysJudgeResultName">
                    </el-table-column>
                    <el-table-column label="客户综合判定" width="120" prop="custJudgeResultName">
                    </el-table-column>
                    <el-table-column label="客户反馈信息" width="150" prop="remark">
                    </el-table-column>
                </el-table>
            </el-card>
            <el-card header="上传附件" style="margin-top: 10px;">
                <el-table :data="fileList">
                    <el-table-column label="文件名" prop="fileName" width="120" />
                    <el-table-column label="图片" width="100">
                        <template #default="scope">
                            <el-image v-if="checkType(scope.row) == 'image'" alt="上传图片" :src="scope.row.fileFullPath"
                                @click="openDialog(scope.row.fileFullPath)"></el-image>
                            <video v-else-if="checkType(scope.row) == 'video'" :src="scope.row.fileFullPath" controls
                                style="width: 100%;height: 100%;"></video>
                        </template>
                    </el-table-column>
                    <el-table-column prop="fileKindName" label="类别">
                    </el-table-column>
                    <el-table-column prop="itemIndex" label="排序">
                    </el-table-column>
                    <el-table-column prop="remark" label="备注">
                    </el-table-column>
                </el-table>
            </el-card>
            <el-card style="margin-top: 10px;margin-bottom:10px">
                <el-form-item label="备注">
                    <el-input style="width: 900px;" v-model="form.remark" :autosize="{ minRows: 2 }" type="textarea"
                        placeholder="请输入" />
                </el-form-item>
            </el-card>
        </el-form>
        <el-dialog v-model="dialogVisible">
            <img :src="dialogImageUrl" alt="Preview Image" w-full style="width: 100%;" />
        </el-dialog>
        <div class="sampleDialog"></div>
        <div class="button-position">
            <el-button @click="updateVisible">取 消</el-button>
        </div>
    </div>
</template>
<script setup>
import { ref, onMounted, getCurrentInstance, createVNode, render } from 'vue';
import Api from '@/api/model/sample'
import { ElMessageBox, ElNotification } from 'element-plus';
import { checkType } from '@/utils/checkType.js'
import tsLayer from '@/utils/useDialog'
const instance = getCurrentInstance()
const emit = defineEmits(['updatetable'])
const props = defineProps({
    paramsData: {
        type: Object,
        defalut: {}
    }
})
const form = ref({})
const formRef = ref(null)
const dataList = ref([])
const fileList = ref([])
const dialogImageUrl = ref()
const dialogVisible = ref(false)
const testRequireList = ref([])
onMounted(() => {
    getInit()
})
const getInit = async () => {
    let res = await Api.testResult.detail.post(props.paramsData)
    console.log(res)
    if (res.code == 200) {
        form.value = res.data
        dataList.value = res.dataList
        fileList.value = res.fileList
        testRequireList.value = res.testRequireList
    }
}
const openDialog = (val) => {
    dialogImageUrl.value = val
    dialogVisible.value = true
}
const toDetail = () => {
    const box = document.querySelector(".sampleDialog")
    let paramsData = {
        id: form.value.sampleAuditId
    }
    import(`@/views/sample/audittable/detailSampleAudit.vue`).then((res) => {
        const form = createVNode(res.default, {
            paramsData,
            onUpdatetable(val) {
                render(null, box)
            }
        })
        tsLayer.open({
            title: '查看样品评审表',
            width: '70%',
            fullScreen: false,
            appContext: instance.appContext,
            box: box,
            content: form
        })
    })
}
const updateVisible = (val) => {
    emit('updatetable')
}

</script>
<style lang="less" scoped>
.borderNone {
    :deep(.el-input__wrapper) {
        box-shadow: 0 0 0 0px var(--el-input-border-color, var(--el-border-color)) inset;
        cursor: default;
        background-color: transparent; //背景颜色透明
        border-bottom: 1px solid #999;
        border-radius: 0;

        .el-input__inner {
            cursor: default !important;
        }
    }

    :deep(.el-textarea__inner) {
        box-shadow: 0 0 0 0px var(--el-input-border-color, var(--el-border-color)) inset;
        cursor: default;
        background-color: transparent; //背景颜色透明
        border-bottom: 1px solid #999;
        border-radius: 0;
    }
}

.link-type,
.link-type:focus {
    color: #337ab7;
    cursor: pointer;
}

.link-type:focus:hover,
.link-type:hover {
    color: #20a0ff
}
</style>